package com.whpu.controller;

import com.whpu.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by RiceBall on 2020/9/29 9:13
 */
@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;

    @RequestMapping("/saveMoney")
    public String saveMoney(String accountId,String accountMoney){
        int id=0;
        double money=0;
        if (!"".equals(accountId)){
            id = Integer.valueOf(accountId);
        }
        if (!"".equals(accountMoney)){
            money = Double.valueOf(accountMoney);
        }
        accountService.saveMoney(id,money);
        return "list";
    }

    @RequestMapping("/transferMoney")
    public String transfer(String fromId,String toId,String money){
        int idFrom = 0;
        int idTo = 0;
        double transferMoney=0;
        if (!"".equals(fromId)){
            idFrom = Integer.valueOf(fromId);
        }
        if (!"".equals(toId)){
            idTo = Integer.valueOf(toId);
        }
        if (!"".equals(money)){
            transferMoney = Double.valueOf(money);
        }
        accountService.transferMoney(idFrom,idTo,transferMoney);
        return "list";
    }
}
